<?php
class BlogModel extends Model{
	public $table='blog';
	//获得所有栏目
	public function addBlog(){
		//有上传缩略图文件时,处理上传文件
		if(!empty($_FILES['thumb']['name'])){
			$upload =new Upload;
			$files = $upload->upload();
			$_POST['thumb']=$files[0]['path'];
		}
		//发表时间
		$_POST['addtime']=time();
		return $this->insert($_POST);
	}
	//修改博客
	public function editBlog(){
		//有上传缩略图文件时,处理上传文件
		if(!empty($_FILES['thumb']['name'])){
			//如果有原图时,删除他..
			if(is_file($_POST['thumb'])){
				unlink($_POST['thumb']);
			}
			$upload =new Upload;
			$files = $upload->upload();
			$_POST['thumb']=$files[0]['path'];
		//发表时间
			$_POST['addtime']=time();
			return $this->where("bid={$_POST['bid']}")->upload($_POST);
		}
	}
	//读取博客
	public function getAll(){
		$result = $this->query('select count(*) as c from blog');
		$page =new Page($result[0]['c'],2);
		$pageStr= $page->show();
		$limit =$page->limit();
		$sql ="select * from blog b  join category c on b.cid=c.cid order by bid desc  LIMIT {$limit}";
		$blog = $this->query($sql);
		return array('blog'=>$blog,'page'=>$pageStr);
	}
}


?>